package community.hospital.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @Author：ydj
 * @Date：2023/1/19 23:14
 */
public class CookieUtil {
    public static String getValue(HttpServletRequest request,String key) {
        if (request == null) {
            throw new RuntimeException("request不能为null");
        }
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            return null;
        }
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(key)) {
                return cookie.getValue();
            }
        }
        return null;
    }
}
